import { EnumBetResult, EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { RecmInfo, RoundInfo } from "../ExecutePlan";
import { IMoneyStrategy } from "../IMoneyStrategy";
import { BossRabbitMoneyStrategy, IBossRabbitMoneyStrategyOption } from "./BossRabitMoneyStrategy";

export interface IMultipleStrategyOption extends IBossRabbitMoneyStrategyOption {
    winMultiple: number;
    failMultiple: number;
    baseMoney: number;
    maxMultiple: number;
}

export class MultipleMoneyStrategy extends BossRabbitMoneyStrategy {
    strategyName: string = "";
    debugCompoenent: string = "";
    moption: IMultipleStrategyOption | null = null;
    winMultiple: number = 2;
    failMultiple: number = 0.5;
    baseMoney: number = 10;
    maxMultiple: number = 8;
    multipleCount: number = 0;
    orecmV: EnumBjlResult = EnumBjlResult.U;
    orecmMoney: number = 0;
    recmV: EnumBjlResult = EnumBjlResult.U;
    recmMoney: number = 0;
    constructor(name: string, option?: IMultipleStrategyOption | null) {
        super(name, option);
        this.strategyName = name;
        if (option) {
            this.moption = option;
        }
        else {
            this.moption = {
                winMultiple: 2,
                failMultiple: 0.5,
                baseMoney: 10,
                maxMultiple: 8,
                winStep: 1,
                failStep: -1,
                prevMoney: 0,
                currentMoney: 100,
            }
        }
    }
    resetStrategy(): void {
        this.winMultiple = this.moption?.winMultiple ?? 2;
        this.failMultiple = this.moption?.failMultiple ?? 0.5;
        this.baseMoney = this.moption?.baseMoney ?? 10;
        this.maxMultiple = this.moption?.maxMultiple ?? 8;
        this.multipleCount = 0;
        this.orecmV = EnumBjlResult.U;
        this.orecmMoney = 0;
        this.recmV = EnumBjlResult.U;
        this.recmMoney = 0;
    }
    showMoney(roundInfo?: RoundInfo): [EnumBjlResult, number] {
        if (roundInfo) {
            if (this.orecmV != EnumBjlResult.U && roundInfo.reverse) {
                this.recmV = this.orecmV == EnumBjlResult.Z ? EnumBjlResult.X : EnumBjlResult.Z;
            }
            else {
                this.recmV = this.orecmV;
            }
        }
        this.recmMoney = this.orecmMoney;
        return [this.recmV, this.recmMoney];
    }
    resetRecm(): void {
    }
    toMoney(roundInfo: RoundInfo, recmInfo: RecmInfo, userRecm: RecmInfo, baseMoney: number): [EnumBjlResult, number] {
        let recmV = roundInfo.userRecm;
        let recmMoney = this.baseMoney;
        let wf = recmInfo.summaryInfo.failMoney - recmInfo.summaryInfo.winMoney;
        if (wf >= 100) {
            if (recmInfo.summaryInfo.prevResult == EnumBetResult.Success) {

            }
            else if (recmInfo.summaryInfo.prevResult == EnumBetResult.Fail) {


            }
            else { }
        }
        else {
            [recmV, recmMoney] = super.toMoney(roundInfo, recmInfo, userRecm, baseMoney);
        }



        let win = Math.abs(recmInfo.summaryInfo.winMoney - recmInfo.summaryInfo.failMoney);

        return [recmV, recmMoney];
    }

    copyValue(valueObj: any): void {
        let obj = valueObj as MultipleMoneyStrategy;
        if (obj) {

            this.winMultiple = obj.winMultiple;
            this.failMultiple = obj.failMultiple;
            this.baseMoney = obj.baseMoney;
            this.maxMultiple = obj.maxMultiple;
            this.multipleCount = obj.multipleCount;
            this.orecmV = obj.orecmV;
            this.orecmMoney = obj.orecmMoney;
            this.recmV = obj.recmV;
            this.recmMoney = obj.recmMoney;
        }

    }
}